import axios from "axios";
import { message } from "antd";


axios.interceptors.request.use((config) => {
  config.headers.Authorization = localStorage.getItem("token");
  return config;
});




axios.interceptors.response.use(

  (response) => {
      // 判断响应的类型，如果是文件流，就直接返回response
  if (response.headers['content-type'] === 'text/plain') {
    return response;
  }
    if (response.data.code !== 2000) {
      message.error(response.data.msg);
      throw new Error(response.data.msg);
    }
    return response.data.content;
  },
  (error) => {
    message.error(error.response.data.msg);
    if (error.response.status === 401) {
      location.href = `${location.origin}/#/login`;
    }
  }
);

export default axios;